package cn.wgx.activiti.demo.web;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * SpringMVC API生成器
 * Swagger2
 *
 */
@Configuration
@EnableSwagger2
@EnableWebMvc
public class Swagger {


    private ApiInfo apiInfo(String module) {
        ApiInfo apiInfo = new ApiInfo(
                "CG中心API",
                "这里是"+module+"模块所有的接口，里边含有说明，仅供测试.返回结果全部为</br>" +
                        "{</br>'success': true/false,</br>" +
                        " 'data': 结果集,</br>" +
                        " 'msg': '错误信息'</br>}</br>" +
                        "如有特殊情况会注明.</br>" +
                        "目前带中文注释的为可用api.",
                "1.0",
                "",
                ApiInfo.DEFAULT_CONTACT,
                "",
                "",
                new ArrayList<VendorExtension>());
        return apiInfo;
    }

    @Bean
    public Docket sysApi() {
        return createDocket("cn.wgx.activiti.demo." ,"web");
    }



    private Docket createDocket(String basepackage,String module){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(module)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basepackage + module))
                .build()
                .apiInfo(apiInfo(module));
    }
}